package com.xiaoming.mall.coupon.controller;

import com.xiaoming.common.utils.R;
import com.xiaoming.mall.coupon.entity.CouponEntity;
import com.xiaoming.mall.coupon.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.Objects;

@RefreshScope
@RequestMapping("coupon/test")
@RestController
public class CouponTestFeignController {

    @Autowired
    private CouponService couponService;

    @RequestMapping("/members")
    public R memberCoupons() {
        // 应该去数据库查用户对于的优惠券，但这个我们简化了，不去数据库查了，构造了一个优惠券给他返回
        CouponEntity couponEntity = new CouponEntity();
        couponEntity.setCouponName("618大促");
        return R.ok().put("coupons", Collections.singletonList(couponEntity));
    }

    @Value("${coupon.user.name}")
    private String name;
    @Value("${coupon.user.age}")
    private Integer age;

    @RequestMapping("/config")
    public R test() {
        return Objects.requireNonNull(R.ok().put("name", name)).put("age", age);
    }

}
